package strCount;

import java.util.Scanner;
import java.util.HashMap;
import java.util.Map;

public class strCount {

	public static void main(String[] args) {
		System.out.println("Please input the string: ");
		Scanner input = new Scanner(System.in);
		String inString = input.nextLine();
		// 将字符按照空格分割开
		String[] reStrings = inString.split(" ");
		Map<String,Integer> map = new HashMap<>();
		for(int i = 0; i < reStrings.length; i++) {
			int count = 0;
			if(map.get(reStrings[i]) != null) {
				count = (Integer)map.get(reStrings[i]);
			}
			// 没有出现过，就将它的值设为1
			if(count == 0) {
				map.put(reStrings[i], 1);
			}
			// 出现过的，就将它的值设为原有的值+1
			else {
				map.put(reStrings[i], count + 1);
			}
		}
		System.out.println(map); //.toString()
		input.close();
 	}
}
